from PyQt5.QtWidgets import QWidget

# 导入窗体内容
from design.signDlg import *

from common.logger import logger
from common.retcode import RetCode
from common.utils import get_file_size_str, center_window_on_screen
from api.user import UserAction

# 创建 MainWin 类并传入Ui_MainWindow
class SignDlg(QWidget, Ui_SignDlg):
	def __init__(self, parent=None):
		super(SignDlg, self).__init__(parent)
		self.setupUi(self)
		center_window_on_screen(self)

		self.pushButtonSign.clicked.connect(self.onClickedSign)

		self._sess_wp = None
		self._parent_win = None

	def reset(self, sess_wp, parent_win):
		self._sess_wp = sess_wp
		self._parent_win = parent_win
		self.labelSignPrize.setText('')
		self.labelFirstLotto.setText('')
		self.labelSecondLotto.setText('')
		self.pushButtonSign.setEnabled(True)

	def onClickedSign(self):
		self.pushButtonSign.setEnabled(False)

		user_action = UserAction(self._sess_wp)
		sign_result = user_action.user_sign()
		print(f'sign_result: {sign_result}')

		self.labelSignPrize.setText(sign_result['sign'])

		prize = sign_result['prize']
		if prize and len(prize) >= 2:
			self.labelFirstLotto.setText(prize[0])
			self.labelSecondLotto.setText(prize[1])

		if self._parent_win:
			self._parent_win.getUserInfo()
			
